﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web.Security;
using SploreServer.Data.Common;
using SploreServer.Data.Session;

namespace SploreServer.Behaviors.Session
{
    public enum OpenSessionResult
    {
        Valid,
        Invalid,
        Failure
    }
    public enum IsSessionOpenResult
    {
        Open,
        Closed,
        Failure
    }
    public enum CloseSessionResult
    {
        Success,
        NoSuchSession,
        Failure
    }
    public class Session : ISession
    {
        public ResultPackage<OpenSessionResult, SessionToken> OpenSession(string theUserName, string thePassword)
        {
            ResultPackage<OpenSessionResult, SessionToken> result;
            try
            {
                if (Membership.ValidateUser(theUserName, thePassword))
                {
                    result = new ResultPackage<OpenSessionResult, SessionToken>(OpenSessionResult.Valid, null);
                }
                else
                {
                    result = new ResultPackage<OpenSessionResult, SessionToken>(OpenSessionResult.Invalid, null);
                }
            }
            catch
            {
                result = new ResultPackage<OpenSessionResult, SessionToken>(OpenSessionResult.Failure, null);
            }
            return result;
        }

        public ResultPackage<IsSessionOpenResult> IsSessionOpen(Data.Session.SessionToken theSessionToken)
        {
            throw new NotImplementedException();
        }

        public ResultPackage<CloseSessionResult> CloseSession(Data.Session.SessionToken theSessionToken)
        {
            throw new NotImplementedException();
        }
    }
}
